#ifndef COMMUNICATIONMANAGER_H
#define COMMUNICATIONMANAGER_H

#include <QObject>
#include <QSerialPort>
#include <QDebug>
#include <QByteArray>
#include <QTimer>
#include <QMessageBox>
#include "protocolhandler.h"



class CommunicationManager : public QObject
{
    Q_OBJECT
public:
    explicit CommunicationManager(QObject *parent = nullptr);


    int received;

    //进行串口通信
    void setupSerialPort(const QString& portName, int baudRate, QSerialPort::Parity parity, QSerialPort::DataBits dataBits, QSerialPort::StopBits stopBits);

    //发送数据
    void sendData(const QByteArray &data);

    //停止发送数据
    void stopSendData();

    //将sendFlag设为true
    void sengFlagTrue();



public slots:
    //接收到数据的槽函数
    void dataReceived();
signals:
    //接收到数据，发射更新主窗口textEdit_data_log显示的信号
    void dataUiUpdata(const QByteArray &data);

private:
    QSerialPort *serial;//定义串口通信对象
    ProtocolHandler *protocol; //定义报文解析对象
    bool sendFlag;

};

#endif // COMMUNICATIONMANAGER_H
